package org.celery.modules.ticket.enums;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 退款状态的枚举类
 */

@Getter
@AllArgsConstructor
public enum refundStatusEnum {
    /**
     * 未付款
     */
    WAITING_FOR_THE_SELLERS_CONSENT("等待卖家同意",  "WAIT_SELLER_AGREE"),
    REFUND_SUCCESSFUL("退款成功",  "REFUND_SUCCESS"),
    REFUND_CLOSED("退款关闭",  "REFUND_CLOSED"),
    TO_BE_MODIFIED_BY_THE_BUYER("待买家修改",  "WAIT_BUYER_MODIFY"),
    WAITING_FOR_BUYER_RETURN("等待买家退货",  "WAIT_BUYER_SEND"),
    WAITING_FOR_SELLER_TO_CONFIRM_RECEIPT("等待卖家确认收货",  "WAIT_SELLER_RECEIVE"),
    ;
    private String name;
    private String value;

    public static String getName(String value) {
        if (value.equals("WAIT_SELLER_AGREE")) {
            return WAITING_FOR_THE_SELLERS_CONSENT.getName();
        } else if (value.equals("REFUND_SUCCESS")) {
            return REFUND_SUCCESSFUL.getName();
        } else if (value.equals("REFUND_CLOSED")) {
            return REFUND_CLOSED.getName();
        } else if (value.equals("WAIT_BUYER_MODIFY")) {
            return TO_BE_MODIFIED_BY_THE_BUYER.getName();
        } else if (value.equals("WAIT_BUYER_SEND")) {
            return WAITING_FOR_BUYER_RETURN.getName();
        } else if (value.equals("WAIT_SELLER_RECEIVE")) {
            return WAITING_FOR_SELLER_TO_CONFIRM_RECEIPT.getName();
        }
        return "";
    }

    /**
     * 根据value获取枚举value值
     * @param name
     * @return
     */
    public static String getValue(String name) {
        if (WAITING_FOR_THE_SELLERS_CONSENT.getValue().equals(name)) {
            return WAITING_FOR_THE_SELLERS_CONSENT.getValue();
        } else if (REFUND_SUCCESSFUL.getValue().equals(name)) {
            return REFUND_SUCCESSFUL.getValue();
        } else if (REFUND_CLOSED.getValue().equals(name)) {
            return REFUND_CLOSED.getValue();
        } else if (TO_BE_MODIFIED_BY_THE_BUYER.getValue().equals(name)) {
            return TO_BE_MODIFIED_BY_THE_BUYER.getValue();
        } else if (WAITING_FOR_BUYER_RETURN.getValue().equals(name)) {
            return WAITING_FOR_BUYER_RETURN.getValue();
        } else if (WAITING_FOR_SELLER_TO_CONFIRM_RECEIPT.getValue().equals(name)) {
            return WAITING_FOR_SELLER_TO_CONFIRM_RECEIPT.getValue();
        }
        return "";
    }

    public JSONObject toJSON() {
        JSONObject jo = new JSONObject();
        jo.put("name", name);
        jo.put("value", value);
        return jo;
    }

    public static List<Map<String, Object>> toList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (refundStatusEnum item : refundStatusEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("name", item.getName());
            map.put("value", item.getValue());
            list.add(map);
        }
        return list;
    }
}
